package com.hf.utils;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;

public class DBUtils {
	
	public static String username = "root";
	public static String password = "";
	public static String url = "jdbc:mysql://127.0.0.1:3306/buerdiy?useUnicode=true&characterEncoding=utf-8";
	public static String driver = "com.mysql.jdbc.Driver";
	
	
	static{
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() throws SQLException{
		
		return  DriverManager.getConnection(url, username, password);
		
	}
	
	public static void close(Connection conn,ResultSet rs,Statement st,PreparedStatement ps){
		
		try{
			if(rs!=null){
				rs.close();
			}
			if(rs!=null){
				rs.close();
			}
			if(ps!=null){
				ps.close();
			}
			if(conn!=null){
				conn.close();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void main(String[] arg0){
		try{
			getConnection();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
